﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace winprop
{
    public class Freq
    {
        private Dictionary<string, double> freqDic = new Dictionary<string, double>();
        public Freq()
        {
            Utility.FileUtil.ReadFileLineContent(System.AppDomain.CurrentDomain.BaseDirectory + "\\freq.txt", line =>
            {
                var arr = line.Split(',');
                freqDic.Add((arr[0]), Convert.ToDouble(arr[1]));
            });
        }

        public double GetFreqByCenterChannelNumber(string channelNumber) {
            int channel = 0;
            bool success = int.TryParse(channelNumber, out channel);

            if (success) {
                if (freqDic.ContainsKey(channelNumber))
                {
                    return freqDic[channelNumber];
                }
                //fdd
                else if (channel < 4000) {
                    return channel;
                }
                else {
                    return 2580;
                }
            }        
            else 
                return 2580;
            }
        
    }
}
